package 多线程.案例.customersProducer;

import 多线程.案例.myBlockingQueue.MyBlockingQueue;

class CustomersProducer {
    //生产者--消费者模型, 一个负责生产, 一个负责消费, 两者通过阻塞队列进行交流
    public static void main(String[] args) {
        MyBlockingQueue queue = new MyBlockingQueue();

        Thread t1 = new Thread(() -> {
            while (true) {
                int value = 0;
                try {
                    value = queue.take();
                    Thread.sleep(500);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("取出 → " + value);
            }
        });

        Thread t2 = new Thread(() -> {
            int i = 0;
            while (true) {
                try {
                    queue.put(++i);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("放入 → " + i);
            }
        });
        t1.start();
        t2.start();

    }
}